package com.java110.mall.cart.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.mall.cart.bmo.housekeepingServPoolUser.IDeleteHousekeepingServPoolUserBMO;
import com.java110.mall.cart.bmo.housekeepingServPoolUser.IGetHousekeepingServPoolUserBMO;
import com.java110.mall.cart.bmo.housekeepingServPoolUser.ISaveHousekeepingServPoolUserBMO;
import com.java110.mall.cart.bmo.housekeepingServPoolUser.IUpdateHousekeepingServPoolUserBMO;
import com.java110.dto.housekeeping.HousekeepingServPoolUserDto;
import com.java110.po.housekeeping.HousekeepingServPoolUserPo;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/housekeepingServPoolUser")
public class HousekeepingServPoolUserApi {

    @Autowired
    private ISaveHousekeepingServPoolUserBMO saveHousekeepingServPoolUserBMOImpl;
    @Autowired
    private IUpdateHousekeepingServPoolUserBMO updateHousekeepingServPoolUserBMOImpl;
    @Autowired
    private IDeleteHousekeepingServPoolUserBMO deleteHousekeepingServPoolUserBMOImpl;

    @Autowired
    private IGetHousekeepingServPoolUserBMO getHousekeepingServPoolUserBMOImpl;

    /**
     * 微信保存消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /housekeepingServPoolUser/saveServPoolUser
     * @path /app/housekeepingServPoolUser/saveHousekeepingServPoolUser
     */
    @RequestMapping(value = "/saveServPoolUser", method = RequestMethod.POST)
    public ResponseEntity<String> saveHousekeepingServPoolUser(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "poolId", "请求报文中未包含poolId");
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");
        Assert.hasKeyAndValue(reqJson, "staffId", "请求报文中未包含staffId");
        Assert.hasKeyAndValue(reqJson, "staffName", "请求报文中未包含staffName");


        HousekeepingServPoolUserPo housekeepingServPoolUserPo = BeanConvertUtil.covertBean(reqJson, HousekeepingServPoolUserPo.class);
        housekeepingServPoolUserPo.setStartTime(DateUtil.getNow("yyyy-MM-dd HH:mm:ss"));
        return saveHousekeepingServPoolUserBMOImpl.save(housekeepingServPoolUserPo);
    }

    /**
     * 微信修改消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /housekeepingServPoolUser/updateHousekeepingServPoolUser
     * @path /app/housekeepingServPoolUser/updateHousekeepingServPoolUser
     */
    @RequestMapping(value = "/updateHousekeepingServPoolUser", method = RequestMethod.POST)
    public ResponseEntity<String> updateHousekeepingServPoolUser(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "poolId", "请求报文中未包含poolId");
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");
        Assert.hasKeyAndValue(reqJson, "staffId", "请求报文中未包含staffId");
        Assert.hasKeyAndValue(reqJson, "staffName", "请求报文中未包含staffName");
        Assert.hasKeyAndValue(reqJson, "preStaffId", "请求报文中未包含preStaffId");
        Assert.hasKeyAndValue(reqJson, "preStaffName", "请求报文中未包含preStaffName");
        Assert.hasKeyAndValue(reqJson, "startTime", "请求报文中未包含startTime");
        Assert.hasKeyAndValue(reqJson, "endTime", "请求报文中未包含endTime");
        Assert.hasKeyAndValue(reqJson, "poolEvent", "请求报文中未包含poolEvent");
        Assert.hasKeyAndValue(reqJson, "preRuId", "请求报文中未包含preRuId");
        Assert.hasKeyAndValue(reqJson, "state", "请求报文中未包含state");
        Assert.hasKeyAndValue(reqJson, "ruId", "ruId不能为空");


        HousekeepingServPoolUserPo housekeepingServPoolUserPo = BeanConvertUtil.covertBean(reqJson, HousekeepingServPoolUserPo.class);
        return updateHousekeepingServPoolUserBMOImpl.update(housekeepingServPoolUserPo);
    }

    /**
     * 微信删除消息模板
     *
     * @param reqJson
     * @return
     * @serviceCode /housekeepingServPoolUser/deleteHousekeepingServPoolUser
     * @path /app/housekeepingServPoolUser/deleteHousekeepingServPoolUser
     */
    @RequestMapping(value = "/deleteHousekeepingServPoolUser", method = RequestMethod.POST)
    public ResponseEntity<String> deleteHousekeepingServPoolUser(@RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "communityId", "小区ID不能为空");

        Assert.hasKeyAndValue(reqJson, "ruId", "ruId不能为空");


        HousekeepingServPoolUserPo housekeepingServPoolUserPo = BeanConvertUtil.covertBean(reqJson, HousekeepingServPoolUserPo.class);
        return deleteHousekeepingServPoolUserBMOImpl.delete(housekeepingServPoolUserPo);
    }

    /**
     * 微信删除消息模板
     *
     * @param shopId 小区ID
     * @return
     * @serviceCode /housekeepingServPoolUser/queryHouseServPoolUser
     * @path /app/housekeepingServPoolUser/queryHousekeepingServPoolUser
     */
    @RequestMapping(value = "/queryHouseServPoolUser", method = RequestMethod.GET)
    public ResponseEntity<String> queryHousekeepingServPoolUser(@RequestParam(value = "shopId") String shopId,
                                                                @RequestParam(value = "poolId") String poolId,
                                                                @RequestParam(value = "page") int page,
                                                                @RequestParam(value = "row") int row) {
        HousekeepingServPoolUserDto housekeepingServPoolUserDto = new HousekeepingServPoolUserDto();
        housekeepingServPoolUserDto.setPage(page);
        housekeepingServPoolUserDto.setRow(row);
        housekeepingServPoolUserDto.setShopId(shopId);
        housekeepingServPoolUserDto.setPoolId(poolId);
        return getHousekeepingServPoolUserBMOImpl.get(housekeepingServPoolUserDto);
    }

    /**
     * 工单派单处理方法
     *
     * @param reqJson
     * @return
     * @serviceCode /housekeepingServPoolUser/poolDispatch
     * @path /app/housekeepingServPoolUser/poolDispatch
     */
    @RequestMapping(value = "/poolDispatch", method = RequestMethod.POST)
    public ResponseEntity<String> poolDispatch(@RequestHeader("user-id") String userId,
                                               @RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "shopId", "商铺不能为空");
        Assert.hasKeyAndValue(reqJson, "staffId", "未包含员工ID信息");
        Assert.hasKeyAndValue(reqJson, "staffName", "未包含员工名称信息");
        Assert.hasKeyAndValue(reqJson, "poolId", "未包含工单信息");
        Assert.hasKeyAndValue(reqJson, "context", "未包含派单内容");
        Assert.hasKeyAndValue(reqJson, "action", "未包含处理动作");
        reqJson.put("userId", userId);
        return saveHousekeepingServPoolUserBMOImpl.poolDispatch(reqJson);
    }
    /**
     * 工单抢单处理方法
     *
     * @param reqJson
     * @return
     * @serviceCode /housekeepingServPoolUser/poolGrabbing
     * @path /app/housekeepingServPoolUser/poolGrabbing
     */
    @RequestMapping(value = "/poolGrabbing", method = RequestMethod.POST)
    public ResponseEntity<String> poolGrabbing(@RequestHeader("user-id") String userId,
                                               @RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "shopId", "商铺不能为空");
        Assert.hasKeyAndValue(reqJson, "poolId", "未包含工单信息");
        reqJson.put("userId", userId);
        return saveHousekeepingServPoolUserBMOImpl.poolGrabbing(reqJson);
    }
    /**
     * 工单撤单处理方法
     *
     * @param reqJson
     * @return
     * @serviceCode /housekeepingServPoolUser/releaseRepair
     * @path /app/housekeepingServPoolUser/releaseRepair
     */
    @RequestMapping(value = "/releaseRepair", method = RequestMethod.POST)
    public ResponseEntity<String> releaseRepair(@RequestHeader("user-id") String userId,
                                               @RequestBody JSONObject reqJson) {
        Assert.hasKeyAndValue(reqJson, "shopId", "商铺不能为空");
        Assert.hasKeyAndValue(reqJson, "poolId", "未包含工单信息");
        reqJson.put("userId", userId);
        return saveHousekeepingServPoolUserBMOImpl.releaseRepair(reqJson);
    }

}
